package com.bafa.front.utils;

import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;

import com.bafa.debug.Debug;
import com.bafa.jdbc.DBAccess;
import com.bafa.services.RetrieveServices;
import com.bafa.services.scorers.FunctionalScorerServices;

public class Ajax {

	
	    public String checkDomain(String domain) {
	        DBAccess db = new DBAccess();
			boolean isExist = false;
			try{
				PreparedStatement statement = db.conn.prepareStatement("select * from subdomains where subdomain=?");
				statement.setString(1,domain);
				ResultSet result = statement.executeQuery();
				while(result.next()){
					isExist=true;
				}
			}catch(SQLException sql){
				
			}
			if(isExist)
				return "Subdomain already exists, please choose another";
			else
				return "";
	    }
		
		public String getScorerName(String id) {
	        DBAccess db = new DBAccess();
			boolean isExist = false;
			Debug.debug(this.getClass(),"getScorerName","Letters passed through "+id);
			try{
				PreparedStatement statement = db.conn.prepareStatement("select * from players where id like ?");
				statement.setString(1,id+"%");
				ResultSet result = statement.executeQuery();
				while(result.next()){
					Debug.debug(this.getClass(),"getScorerName","First Name is "+RetrieveServices.getPlayer(result.getString("id")).getFirstname());
					return RetrieveServices.getPlayer(result.getString("id")).getFirstname();
					
				}
			}catch(SQLException sql){
				
			}
			return "";
	    }
		
		
	
}
